package org.example.repository;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.example.mapper.SysStockMapper;
import org.example.model.po.SysStockPO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Repository
public class SysStockRepository {
    @Resource
    private SysStockMapper sysStockMapper;

    @DS("db_stock")
    public void updateStock(SysStockPO sysStockPO) {
        sysStockMapper.update(sysStockPO, new LambdaUpdateWrapper<SysStockPO>()
                .eq(SysStockPO::getGoodsId, sysStockPO.getGoodsId())
                .setSql(" num = num - 1")
        );
    }
}
